-- @owner: opentestcase023
-- @date: 2022/02/24
-- @testpoint: 在从src视图中删除元素时删除src表中id1=1的行  each row

--step1:建表;expect:成功
drop table if exists t_trigger_src_00064 cascade;
create table t_trigger_src_00064(id1 int, id2 int, id3 int) with (storage_type=ustore);

--step2:在从src视图中删除元素时删除src表中id1=1的行  each row;expect:成功
create or replace view t_trigger_src_00064_view1 as select * from t_trigger_src_00064;
create or replace function insert_func()
returns trigger as $$
begin
delete from t_trigger_src_00064 where id1=1;
return new;
end;
$$language plpgsql;
/
drop trigger if exists insert_trigger_1 on t_trigger_src_00064_view1;
create trigger insert_trigger_1
instead of delete on t_trigger_src_00064_view1
for each row
execute procedure insert_func();
/
insert into t_trigger_src_00064 values(1,1,1),(2,2,2),(3,3,3);
select * from t_trigger_src_00064_view1 order by id1;
delete from t_trigger_src_00064_view1 where id1=2;
select * from t_trigger_src_00064_view1 order by id1;

--step3:清理环境;expect:成功
drop trigger if exists insert_trigger_1 on t_trigger_src_00064_view1;
drop view if exists t_trigger_src_00064_view1;
drop table if exists t_trigger_src_00064 cascade;
drop function if exists insert_func;